package org.ozsoft.texasholdem.bots;
import java.util.*;
import org.ozsoft.texasholdem.Action;

public class LearningTree 
{
	ActionNode startNode;
	ActionNode lastAddedNode;
	public LearningTree()
	{
		this.startNode = new ActionNode(null,null);
		this.lastAddedNode = null;
	}
	
	public void setShowDownNode(double EHS)
	{
		lastAddedNode.setEHS(EHS);
		ActionNode iterateNode;
		do
		{
			iterateNode = lastAddedNode.getParent();
			iterateNode.setEHS(EHS);
		} while (iterateNode != null);
	}
	
	public ActionNode checkSequence(Stack<Action> actions)
	{
		Action currentAction;
		ActionNode currentNode = startNode;
		while(!actions.isEmpty())
		{
			boolean childFound = false;
			currentAction = actions.pop();
			for(ActionNode child : currentNode.getChildren())
			{
				if(child.equals(currentAction))
				{
					currentNode = child;
					childFound = true;
				}
			}
			if(!childFound)
			{
				lastAddedNode = currentNode.addChild(currentAction);
			}
		}
		return currentNode;
	}
}
